package com.sailmi.system.feign;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sailmi.common.tool.api.R;
import com.sailmi.system.entity.Enterprise;
import com.sailmi.system.entity.UserEnterprise;
import com.sailmi.system.vo.EnterpriseVO;
import com.sailmi.system.service.IEnterpriseService;
import com.sailmi.system.service.IUserEnterpriseService;
import com.sailmi.system.wrapper.EnterpriseWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/enterprise")
public class EnterpriseFeignController implements IEnterpriseFeign {
	@Autowired
	private IEnterpriseService enterpriseService;
	@Autowired
	private IUserEnterpriseService userEnterpriseService;

	@Override
	@GetMapping( "/enter-detail")
	public R<EnterpriseVO> detailInfo(Enterprise enterprise) {
		Enterprise byId = enterpriseService.getById(enterprise.getId());
		return R.data(
			EnterpriseWrapper.build().entityVO(byId)
		);
	}

	@Override
	@PostMapping("/enter-update")
	public R update(@Valid Enterprise enterprise) {
		boolean b = enterpriseService.updateById(enterprise);
		return R.status(b);
	}

	@Override
	@PostMapping("/userenter-detail")
	public R<UserEnterprise> queryUserEnterpriseInfo(String enterpriseId) {
		QueryWrapper<UserEnterprise> userEnterpriseQueryWrapper = new QueryWrapper<>();
		userEnterpriseQueryWrapper.eq("enterprise_id",enterpriseId).eq("status",1);
		UserEnterprise one = userEnterpriseService.getOne(userEnterpriseQueryWrapper);
		return R.data(one);
	}
}
